import { ItemData } from "../../resource/info/ItemData";
import { Tooltip } from "../common/tooltip/Tooltip";
import { ObjCreate } from "../common/ObjCreate";
import { LayerManager } from "../../manager/LayerManager";
import { Global } from "../../../../com/gengine/global/Global";
import { TaskInfo } from "../../model/TaskInfo";
import { ETaskGroup } from "../../../../Message/Game/ETaskGroup";
import { ETaskStatus } from "../../../../Message/Game/ETaskStatus";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { EReward } from "../../../../Message/Public/EReward";
import { ItemConfig } from "../../resource/ItemConfig";
import { ECareer } from "../../../../Message/Public/ECareer";
import { Cache } from "../../cache/Cache";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { SkillStateConfig } from "../../resource/SkillStateConfig";
import { GButton } from "../../../../com/mui/controls/GButton";
//class TaskRwardPanel
    
    export  class TaskRwardPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._textField = new Object /* flash.text.TextField */();
            this._textField.textColor = 11661311;
            this._textField.selectable = false;
            this._textField.multiline = true;
            this._textField.wordWrap = true;
            this._textField.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._textField.width = 344;
            addChild(this._textField);
            this._textField.addEventListener(flash.events.TextEvent.LINK, this.onTextLinkHandler);
            return;
        }

        /* internal  */onTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=int(arg1.text);
            var loc2=new ItemData(loc1);
            if (!TaskRwardPanel._toolTip) 
            {
                TaskRwardPanel._toolTip = new Tooltip();
                TaskRwardPanel._closeBtn = ObjCreate.createGButton("", TaskRwardPanel._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
                TaskRwardPanel._spTooltipContainer.addChild(TaskRwardPanel._toolTip);
                TaskRwardPanel._spTooltipContainer.addChild(TaskRwardPanel._closeBtn);
            }
            TaskRwardPanel._point.x = mouseX;
            TaskRwardPanel._point.y = mouseY;
            TaskRwardPanel._point = localToGlobal(TaskRwardPanel._point);
            TaskRwardPanel._toolTip.data = loc2.getToolTipData();
            TaskRwardPanel._spTooltipContainer.x = TaskRwardPanel._point.x;
            TaskRwardPanel._spTooltipContainer.y = TaskRwardPanel._point.y;
            LayerManager.toolTipLayer.addChild(TaskRwardPanel._spTooltipContainer);
            TaskRwardPanel._closeBtn.x = TaskRwardPanel._toolTip.width - 24;
            TaskRwardPanel._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeTootipHandler);
            this.resetToolTipPosition();
            return;
        }

        /* internal  */resetToolTipPosition(): void
        {
            if (TaskRwardPanel._spTooltipContainer.x > Global.stage.stageWidth - TaskRwardPanel._spTooltipContainer.width - 6) 
            {
                TaskRwardPanel._spTooltipContainer.x = TaskRwardPanel._spTooltipContainer.x - TaskRwardPanel._spTooltipContainer.width - 6;
            }
            var loc1=1;
            TaskRwardPanel._spTooltipContainer.y = TaskRwardPanel._spTooltipContainer.y - TaskRwardPanel._spTooltipContainer.height - 6;
            if (TaskRwardPanel._spTooltipContainer.y < 0) 
            {
                TaskRwardPanel._spTooltipContainer.y = 0;
            }
            return;
        }

        /* internal  */closeTootipHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (TaskRwardPanel._spTooltipContainer && TaskRwardPanel._spTooltipContainer.parent) 
            {
                TaskRwardPanel._spTooltipContainer.parent.removeChild(TaskRwardPanel._spTooltipContainer);
            }
            return;
        }

        public updateData(arg1: TaskInfo): void
        {
            var loc3=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            this.dispose();
            if (!arg1) 
            {
                this._textField.htmlText = "";
                return;
            }
            if (arg1.sTask.group == ETaskGroup._ETaskGroupTransport) 
            {
                if (arg1.status != ETaskStatus._ETaskStatusHadFail) 
                {
                    this._textField.htmlText = HTMLUtil.addColor(Language.getString(20740) + "    " + Language.getString(20741), "#fcfeca");
                }
                else 
                {
                    this._textField.htmlText = HTMLUtil.addColor(Language.getString(20740), "#fcfeca");
                }
                return;
            }
            if (arg1.sTask.group == ETaskGroup._ETaskGroupLoopBook) 
            {
                this._textField.htmlText = HTMLUtil.addColor(Language.getString(20740), "#fcfeca");
                return;
            }
            if (arg1.sTask.group == ETaskGroup._ETaskGroupSchool && arg1.status == ETaskStatus._ETaskStatusCanGet) 
            {
                this._textField.htmlText = HTMLUtil.addColor(Language.getString(20740) + "    " + Language.getString(20742), "#fcfeca");
                return;
            }
            var loc1=arg1.sTask.rewards;
            var loc2="";
            this._textField.htmlText = "";
            var loc4=0;
            var loc5=loc1.length;
            label849: while (loc4 < loc5) 
            {
                loc3 = loc1[loc4];
                var loc9=loc3.type;
                switch (loc9) 
                {
                    case EReward._ERewardItem:
                    {
                        if ((loc7 = ItemConfig.instance.getInfoByCode(loc3.code).item) != null) 
                        {
                            if (!(loc7.career == ECareer._ECareerNo) && !(loc7.career & Cache.instance.role.roleInfo.career)) 
                            {
                                ++loc4;
                                continue label849;
                            }
                            else if (loc6 = GameDefConfig.instance.getRewardDef(loc3.type)) 
                            {
                                loc2 = loc2 + (loc6.name.split("　").join("") + "：");
                                loc2 = loc2 + ("<u><a href=\'event:" + loc7.code + "\'>" + HTMLUtil.addColor(loc7.name, ColorConfig.instance.getItemColor(loc7.color).color) + "</a></u>×" + loc3.num);
                            }
                        }
                        break;
                    }
                    case EReward._ERewardBufferGroup:
                    {
                        if (loc8 = SkillStateConfig.instance.getInfoByName(loc3.code)) 
                        {
                            if (loc6 = GameDefConfig.instance.getRewardDef(loc3.type)) 
                            {
                                loc2 = loc2 + (loc6.name.split("　").join("") + "：");
                                loc2 = loc2 + HTMLUtil.addColor(loc8.name, "#fcfeca");
                            }
                        }
                        break;
                    }
                    default:
                    {
                        if (loc6 = GameDefConfig.instance.getRewardDef(loc3.type)) 
                        {
                            loc2 = loc2 + (loc6.name.split("　").join("") + "：");
                            loc2 = loc2 + HTMLUtil.addColor(loc3.num.toString(), "#fcfeca");
                        }
                    }
                }
                loc2 = loc2 + "    ";
                ++loc4;
            }
            this._textField.htmlText = loc2;
            return;
        }

        public dispose(): void
        {
            this.closeTootipHandler(null);
            return;
        }

        /* internal */ /* var */_textField: Object /* flash.text.TextField */;

        /* internal */ static /* var */_toolTip: Tooltip;

        /* internal */ static /* var */_closeBtn: GButton;

        /* internal */ static /* var */_spTooltipContainer: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_point: Object /* flash.geom.Point */;
    }

            TaskRwardPanel._spTooltipContainer = new Object /* flash.display.Sprite */();
            TaskRwardPanel._point = new Object /* flash.geom.Point */();
        